#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void inputString(const char * prompt, char * input)
{
	input[0] = 0;
	printf("%s", prompt);
	scanf("%[^\n]", input);
	fflush(stdin);
}
void stringcleaning(char * string)
{
	int i, k, j;
	for(i=0;  i<strlen(string); i++)
	{
		if(isspace(string[i])!=0)
		{
			j=i+1;
			k=0;
			string[i]=' ';
			while(isspace(string[i+1])!=0)
			{
				k++;
				j=j+1;
			}
			memmove(string + i + 1, string + i + k + 1, (strlen(string) - i - k)*sizeof(char));
		}
	}
}

void main()
{
	FILE * outFile = NULL;
	char string[1000]="", outfile[1000]="";
	inputString("Input string: ", string);
	inputString("Input output file name: ", outfile);
	stringcleaning(string);
	outFile=fopen(outfile, "w");
	fputs(string, outFile);
	fclose(outFile);
	printf("Cleaned string: %s\n", string);
	system("PAUSE");
}
